<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" href="<%=basePath %>css/cssreset.css">
        <link rel="stylesheet" href="<%=basePath %>css/style.css">
        <link rel="stylesheet" href="<%=basePath %>css/style2.css">
		<script src="<%=basePath %>js/jquery-1.11.1.min.js"></script>
		 <script>
		       $(function(){
			    	$(".shenpi").click(function(e){
			    		// alert(1);
			        e.preventDefault();
			        $('body').css("overflow","hidden");
			        $("#cover").css("display","block");
			        $("#cover").animate({
			            width: "100%",
			            height: "1800px",
			            top: "0",
			            left: "0"
			        },10);
			        /*$("#cover-content").animate({
			            width: "300px",
			            height: "300px",
			        },800);*/
			    });
			    	$(".newht").click(function(e){
			        e.preventDefault();
			        $('body').css("overflow","hidden");
			        $("#cover4").css("display","block");
			        $("#cover4").animate({
			            width: "100%",
			            height: "1800px",
			            top: "0",
			            left: "0"
			        },10);
			        
			    });
			    $(".close").click(function(){
			    	$('body').css("overflow","scroll");
			        $("#cover4").removeAttr("style");
			        $("#cover-content3").removeAttr("style");
			    });
			    $(".mine").click(function(e){
			        e.preventDefault();
			        $('body').css("overflow","hidden");
			        $("#cover5").css("display","block");
			        $("#cover5").animate({
			            width: "100%",
			            height: "1800px",
			            top: "0",
			            left: "0"
			        },10);
			        
			    });
			    $(".close").click(function(){
			    	$('body').css("overflow","scroll");
			        $("#cover5").removeAttr("style");
			        $("#cover-content4").removeAttr("style");
			    });
			    
			    
			    $(".close").click(function(){
			    	$('body').css("overflow","scroll");
			        $("#cover").removeAttr("style");
			        $("#cover-content").removeAttr("style");
			    });
			    $('.check1').click(function(event) {
			    	 //$('.back').css('display', 'none'); 
			    	/* $('#smallig').css('display', 'none'); */
			    	$('.checkok').css('display', 'block');
			    	$('.del').css('display', 'block');
			    	$('.shift').css('display', 'block');
			    	$('.close2').css('display', 'block');
			    });
			    $('.close2').click(function(event) {
			    	$('.back').css('display', 'block');
			    	$('#smallig').css('display', 'block');
			    	$('.smalltitle p').css('display', 'block');
			    	$('.checkok').css('display', 'none');
			    	$('.del').css('display', 'none');
			    	$('.shift').css('display', 'none');
			    	$('.close2').css('display', 'none');
			    });
			});
		  </script> 
		  <script>
		  	function selectCheck(){
	    	   var judge = $("#selectCheck").val();
	    	   var objs = document.getElementsByName("items");
			   if(judge == 1){
				   for(var i = 0,l = objs.length;i < l;i++){
		    		   objs[i].checked = true;
		    	   }
				   $("#selectCheck").val(0);
	    	   }else{
	    		   for(var i = 0,l = objs.length;i < l;i++){
		    		   objs[i].checked = false;
		    	   }
	    		   $("#selectCheck").val(1);
	    	   }
	    	   
	    	   checkedShow();
	       }
		  	
		  	function checkedShow(){
		  		var str = "";
	    	    var number = 0;
	    	    var obj = document.getElementsByName("items");
				for(var i = 0,l = obj.length;i < l;i++){
					if(obj[i].checked){
						str += obj[i].value+",";
						number++;
					}
				}    	   
	    			
	    	    if(str == ""){
	    	    	 $(".yezi1").hide();
		    		   $('#fuzeren').css('display', 'block');
		    		   $('.smalltitle p').css('display', 'block');
		    		   $('.back').css('display', 'block'); 
	    	    }else{
	    	    	$('.smalltitle p').css('display', 'none');
		    		   $(".staff_id").html(str);
		    		   $(".yezi1").show();
		    		   $("#number").html(number);
		    		   $('.back').css('display', 'none'); 
	    	   }
		  	}
		  	 
		  </script>
        
    </head>
    <body>
    	<div class="bigbox2 bbigbox changebox">
    		<nav class="daohan">
    			<span class="scolor"></span>
    			<ul>
    				<li><a href="<%=basePath %>page/originalIndex.jsp"><p class="mline"><span class="smallicon"></span><span class="navtxt">首 页</span></p></a></li>
    				<li><a href="<%=basePath %>client/findByIndex.action"><p class="mline"><span class="smallicon one1" ></span><span class="navtxt" >客 户</span></p></a></li>
    				<li><a href="<%=basePath %>sale/findSale.action"><p class="mline"><span class="smallicon one2"></span><span class="navtxt">销 售 机 会</span></p></a></li>
    				<li><a href="<%=basePath %>contact/page.action"><p class="mline"><span class="smallicon one3"></span><span class="navtxt">联 系 人</span></p></a></li>
    				<li><a href="<%=basePath %>contract/findByAlls.action" id="sline"><p class="mline"><span class="smallicon one4" id="current21"></span><span class="navtxt" id="current2">合 同</span></p></a></li>
    			 <li><a href="<%=basePath %>page/pacts.jsp"><p class="mline"><span class="smallicon one8"></span><span class="navtxt">合 同 审 批</span></p></a></li>
    				<c:if test="${sessionScope.backstage == 1}">
   						<li><a href="<%=basePath %>staff/selectTree.action"><p class="mline"><span class="smallicon one5"></span><span class="navtxt">后 台 管 理</span></p></a></li>
    				</c:if>
    			</ul>
    		</nav>
    		<div class="showbox2">
	    		<p class="title">合 同</p>
	    			<div class="aaa aaa2">
	    			<div class="smalltitle">
	 				<span class="back"><&nbsp;&nbsp;&nbsp;&nbsp;负责的合同</span>
					 <p class="yezi">
						<a href="#" class="light3"><span class="imgmove"><img src="<%=basePath %>images/icon (14).png" alt=""></span>&nbsp;&nbsp;导出</a>
						 <a href="#" class="newht" onclick="updateStaffName()"><span class="imgmove imgmove2"><img src="<%=basePath %>images/icon (23).png" alt=""></span>&nbsp;&nbsp;新建合同</a>
						 <a href="#"><span class="imgmove imgmove2"><img src="<%=basePath %>images/icon (16).png" alt=""></span>&nbsp;&nbsp;导入</a>
					 </p>
					 <span class="yezi1">
					 <a href="#" class="smallig"><img src="<%=basePath %>images/icon (20).png" alt=""></a>
					 <h4 class="checkok">已选择 <span style="color:#1fd4fb;" id = "number"> </span>项</h4>
					 <span class="del" onclick="deleteContract()"><img src="<%=basePath %>images/icon (17).png" alt="" style="position: absolute;bottom: 19px;left: -22px;">&nbsp;删除</span>
					  <span class="del shift mine" "><img src="<%=basePath %>images/icon (25).png" alt="" style="position: absolute;bottom: 18px;left: -29px;">&nbsp;转移</span>
	    				<span class="close2">
	    					<img src="<%=basePath %>images/icon (18).png" alt="">
	    				</span>
	    				</span>
	    				</div>
	    				<span class="blueline"></span>
	    				<div class="tab">
	    					<p class="tline">
	    						<span class="xuanze"><input type="checkbox" class="check1" id="selectCheck" value="1" onclick="selectCheck()"></span>
			    		            <span>客户姓名</span>
			    		            <span class="cname">合同类型</span>
			    		            <span>开始日期</span>
			    		            <span class="cphone">总金额</span>
			    		            <span class="cphone">付款方式</span>
			    		            <span class="cdate">合同状态</span>
			    		            <span class="cdate2">合同所有人</span>
	    					</p>
	    					
	    					<c:forEach items="${contracts}" var="contract">
	    						<p class="tline tline2">
		    						<span class="xuanze">
		    							<input type="checkbox" class="check1" value="${contract.contractId}" name="items" onclick="checkedShow()">
		    						</span>
			    		            <span><a href="<%=basePath %>contract/selectById.action?id=${contract.contractId}" style="font-size: 14px;text-decoration:none;color:#000">${contract.clientName}</a></span>
			    		            <span class="cname">${contract.contracttype }</span>
			    		            <span>
										<fmt:formatDate value="${contract.contractCloseDate}" type="date"/>
									</span>
			    		            <span class="cphone">${contract.contractAmount}</span>
			    		            <span class="cphone">${contract.contractPaymode}</span>
			    		            <span class="cdate">${contract.contractStatus}</span>
			    		            <span class="cdate2">${contract.staffName}</span>
		    					</p>
	    					</c:forEach>
	    					
	    					 
	    				</div>
	    				<div id="cover4">
						<div id="cover-bg3"></div>
						<div id="cover-content3">
										<h4>新 建 合 同<span class="close"></span></h4>
										<p class="main">
											<span class="leftmain">业务类型</span>
											
											
											<span class="name" id="contractBusinesstype">默认业务类型</span>
											
										</p>
										<p class="main">
											<span class="leftmain">主 题&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
											<input type="text" id="contractTitle" placeholder="&nbsp;&nbsp;请输入主题 " class="shurukuang">
										</p>
										
										
										<p class="main">
											<span class="leftmain">客 户&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
											<select id="onecli" class="shenfenselect shenfenselect3" onchange="selectSale()">
									            <option>&nbsp;请选择客户</option>
									           
									        </select>
										</p>
										<p class="main">
											<span class="leftmain">销 售 机 会</span>
											<select id="saleId" class="shenfenselect shenfenselect3">
									            <option>&nbsp;请选择销售机会</option>
									           
									        </select>
										</p>
										<p class="main">
											<span class="leftmain">总 金 额&nbsp;&nbsp;&nbsp;&nbsp;</span>
											<input type="text" id="contractAmount" placeholder="&nbsp;&nbsp;请输入总金额 " class="shurukuang">
										</p>
										<p class="main">
											<span class="leftmain">付 款 方 式</span>
											<select id="onecl" class="shenfenselect shenfenselect3">
							            <option value="支票">&nbsp;支票</option>
							            <option value="现金">&nbsp;现金</option>
							            <option value="银行转账">&nbsp;银行转账</option>
							            <option value="其他">&nbsp;其他</option>
							           
							        </select>
										</p>
										<p class="main">
											<span class="leftmain">开 始 日 期</span>
											<input type="text" id="contractStartDate" placeholder="&nbsp;&nbsp;请输入开始日期 " class="shurukuang Wdate" style="height: 30px;1px solid #bfbfbf;"   onfocus="WdatePicker({skin:'whyGreen',dateFmt: 'yyyy-MM-dd', readOnly:true})">
										</p>
										<p class="main">
											<span class="leftmain">结 束 日 期</span>
											
											<input type="text" id="contractCloseDate" placeholder="&nbsp;&nbsp;请输入结束日期 " class="shurukuang Wdate" style="height: 30px;1px solid #bfbfbf;"   onfocus="WdatePicker({skin:'whyGreen',dateFmt: 'yyyy-MM-dd', readOnly:true})">
										</p>
										
										<p class="main">
											<span class="leftmain">签 约  日 期</span>
											
											<input type="text" id="contractSigndate" placeholder="&nbsp;&nbsp;请输入签约日期 " class="shurukuang Wdate" style="height: 30px;1px solid #bfbfbf;"   onfocus="WdatePicker({skin:'whyGreen',dateFmt: 'yyyy-MM-dd', readOnly:true})">
										</p>
										<p class="main">
											<span class="leftmain">合 同 所 有 人</span>
											<span class="none" id="staff_name"></span>
										</p>
										
										<p class="main">
											<span class="leftmain">合 同 编 号</span>
											<input type="text" id="contractCode" placeholder="&nbsp;&nbsp; " class="shurukuang">
										</p>
										
										<p class="main">
											<span class="leftmain">合 同 正 文</span>
											<textarea rows="" cols="" id="contractContent" cols="30" rows="10"></textarea>
										</p>
										
										<p class="main">
											<span class="leftmain">产 品&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
											<input type="text" id="contractProduct" placeholder="&nbsp;&nbsp; " class="shurukuang">
										</p>
										
										<p class="main">
											<span class="leftmain">我 方 签 约 人&nbsp;&nbsp;&nbsp;&nbsp;</span>
											<input type="text" id="contractSigner" placeholder="&nbsp;&nbsp; " class="shurukuang" style="margin-left:-7px">
										</p>
										
										<p class="main">
											<span class="leftmain">我客户方签约人</span>
											<input type="text" id="contractCustomerSigner" placeholder="&nbsp;&nbsp; " class="shurukuang">
										</p>
										
										<p class="main">
											<span class="leftmain">所 属 部 门</span>
											<select id="onedeps" class="shenfenselect shenfenselect3">
									            <option>请选择</option>
									            
									        </select>
										</p>
										
										<p class="main">
											<span class="leftmain">合 同 类 型</span>
											<select id="onecees" class="shenfenselect shenfenselect3">
									            
									        </select>
										</p>
										
										<p class="main">
											<span class="leftmain">合 同 状 态</span>
											<select id="contractStatus" class="shenfenselect shenfenselect3">
									            <option value="">&nbsp;请选择合同状态</option>
									            <option value="执行中">&nbsp;执行中</option>
									            <option value="结束">&nbsp;结束</option>
									            <option value="意外终止">&nbsp;意外终止</option>
									            
									        </select>
										</p>
										<p class="main">
											<span class="leftmain">签 约 备 注</span>
											<input type="text" value="" id="contractSignremarks" class="shurukuang">
										</p>
										
										<p class="main" style="padding-bottom:30px;">
											
											<button class="btn1 btn2" onclick="saveContract()">保存</button>
											<button class="btn1 btn3">取消</button>
										</p>
						</div>
						</div>
						
						<div id="cover5">
						<div id="cover-bg4"></div>
						<form action="" id="cover-content4">
										<h4>转 移 合 同<span class="close"></span></h4>
										<p class="main">是否将选中的合同转移给其他负责人？转移成功之后，该操作将无法恢复。</p>
										<p class="main">
											<span class="leftmain">机 会 类 型</span>
											<select id="one" class="shenfenselect shenfenselect3">
									            <option>&nbsp;请选择机会类型</option>
									            <option>2</option>
									            <option>3</option>
									            <option>4</option>
									            <option>5</option>
									            <option>6</option>
									            <option>7</option>
									            <option>8</option>
									            <option>9</option>
									        </select>
										</p>
										
										
										<p class="main">
											
											<button class="btn1 btn2">保存</button>
											<button class="btn1 btn3">取消</button>
										</p>
						</form>
						</div>
					 </div>
	    		</div>
	    	</div>
	    </div>
    	<div style="display: none">
    		<p class="staff_id" ></p>
    	</div>
    	<script src="${pageContext.request.contextPath}/salejihui/My97DatePicker/WdatePicker.js"></script>
    </body>
    <script type="text/javascript">
    	
    function deleteContract(){
    	  	var staff_id = $(".staff_id").html();
    	  	staff_id = staff_id.substring(0,staff_id.length-1);
    	  	$.ajax({
				type:"post",
				url:"<%=basePath %>contract/deletes.action",
				data:"ids="+staff_id,
				success:function(data){
					alert(data);
					location.href="<%=basePath %>contract/findByAlls.action";
				},
				error:function(e){
					alert("发生未知错误请刷新页面");
				}

	   		 });
    	}
    	
    function updateStaffName(){
    	$.ajax({
			type:"post",
			url:"<%=basePath %>contract/findCompactGenres.action",
			success:function(data){
				$("#onecees").html("");
				var dep = eval("("+data+")");
					for(var i=0;i<dep.length;i++){
						var depar = dep[i];
						var depass = "<option value='"+depar.compactName+"'>"+depar.compactName+"</option>";
						$("#onecees").append(depass);
					}
			},
			error:function(e){
				alert("发生未知错误请刷新页面");
			}

   		 });
    	
    	$.ajax({
			type:"post",
			url:"<%=basePath %>staff/findAllDeps.action",
			success:function(data){
				$("#onedeps").html("");
	    	    var baa = "<option value=''>请选择</option>";
	    	    $("#onedeps").append(baa);
				var dep = eval("("+data+")");
				for(var i=0;i<dep.length;i++){
					var depar = dep[i];
					var depass = "<option value='"+depar.department_id+"'>"+ depar.department_name+"</option>";
					$("#onedeps").append(depass);
				}
				$.ajax({
					type:"post",
					url:"<%=basePath %>contract/findStaffSession.action",
					success:function(staffs){
						var staff = eval("("+staffs+")");
						$("#staff_name").html(staff[0].staff_name);
						$("#onedeps option[value='"+staff[0].staff_departmentId+"']").attr("selected",true);
					},
					error:function(e){
						alert("发生未知错误请刷新页面");
					}
		   		 });
			},
			error:function(e){
				alert("发生未知错误请刷新页面");
			}
   		 });
    	
    	$.ajax({
			type:"post",
			url:"<%=basePath %>contract/findClients.action",
			success:function(data){
				$("#onecli").html("");
	    	    var baa = "<option value='0'>请选择</option>";
	    	    $("#onecli").append(baa);
				var dep = eval("("+data+")");
					for(var i=0;i<dep.length;i++){
						var depar = dep[i];
						var depass = "<option value='"+depar.client_id+"'> "+ depar.client_name+"</option>";
						$("#onecli").append(depass);
					}
			},
			error:function(e){
				alert("发生未知错误请刷新页面");
			}

   		 });
    	
    }
    
    function saveContract(){
    	var onecli = $("#onecli").val();
    	if(onecli == 0){
    		alert("客户不能为空");
    		return;
    	}
    	onecli = $("#onecli option:selected").text();
    	var contractBusinesstype = "默认业务类型";
    	var saleI = $("#saleId").val();
    	var contractTitle = $("#contractTitle").val();
    	var contractAmoun = $("#contractAmount").val();
    	var onecl = $("#onecl option:selected").val();
    	var contractStartDat = $("#contractStartDate").val();
    	var contractCloseDat = $("#contractCloseDate").val();
    	var contractSigndate = $("#contractSigndate").val();
    	var contractContent = $("#contractContent").val();
    	var staff_name= $("#staff_name").html();
    	var contractCod = $("#contractCode").val();
    	var contractProduc = $("#contractProduct").val();
    	var contractSigne = $("#contractSigner").val();
    	var contractCustomerSigne = $("#contractCustomerSigner").val();
    	var onedep = $("#onedeps").find("option:selected").text();
    	var onecee = $("#onecees").find("option:selected").text();
    	var contractStatu = $("#contractStatus").find("option:selected").val();
    	var remark = $("#contractSignremarks").val();
    	var usdata = {contractBusinesstype:contractBusinesstype,clientName:onecli,saleId:saleI,
    				  contractTitle:contractTitle,contractAmount:contractAmoun,contractPaymode:onecl,
    				  contractStartDate:contractStartDat,contractCloseDate:contractCloseDat,staffName:staff_name,
    				  contractCode:contractCod,contractProduct:contractProduc,contractSigner:contractSigne,contractCustomerSigner:contractCustomerSigne,
    				  departmentName:onedep,contracttype:onecee,contractStatus:contractStatu,contractSigndate:contractSigndate,
    				  contractContent:contractContent,contractSignremark:remark};
    	$.ajax({
			type:"post",
			url:"<%=basePath %>contract/saveContract.action",
			data:usdata,
			success:function(data){
				alert(data);
				if(data == "新增成功"){
					location.href="<%=basePath %>contract/findByAlls.action";
				}
			},
			error:function(e){
				alert("发生未知错误请刷新页面");
			}

   		 });
    }
    
    function selectSale(){
    	var id = $("#onecli").val();
    	$.ajax({
			type:"post",
			url:"<%=basePath %>contract/findxiaoshoujihui.action",
			data:"id="+id,
			success:function(data){
				$("#saleId").html("");
	    	    var baa = "<option value=''>请选择</option>";
	    	    $("#saleId").append(baa);
				var dep = eval("("+data+")");
				for(var i=0;i<dep.length;i++){
					var depar = dep[i];
					var depass = "<option value='"+depar.saleId+"'> "+ depar.saleOpportunityName+"</option>";
					$("#saleId").append(depass);
				}
			},
			error:function(e){
				alert("发生未知错误请刷新页面");
			}

   		 });
    }
    
    </script>
</html>
